#include "TimePage.h"
#include "MachineDependents.h"
#include "CommandExecutor.h"

void TimePage::paint() {
    if (focus) {
        EditablePage::paint();
    } else {

        std::tm nowTm = DateTimeUtility::getTime();

        resetStream();
        strStream << "time:" << std::setw(8) << std::put_time(&nowTm,"%T") << std::setw(3) << pageNum;
        std::string first = strStream.str();

        resetStream();
        strStream << "week:" << nowTm.tm_wday << std::setw(10) << std::right << LOCK_STATUS[AuthenticatorSingleton::instance().mpermit];//
        std::string second = strStream.str();

        resetStream();
        strStream << "date:" <<std::setw(11) << std::put_time(&nowTm,"%F");
        std::string third = strStream.str();

        resetStream();
        strStream << "remain:" <<std::setw(9) << mloopManager.getManualModeRemainTime();
        std::string four  = strStream.str();
        // (int)LoopManager.getInstance().getManualModalRemainTime()))

        screen.show(&first, &second, &third, &four);
    }
}



void TimePage::saveValue() {
        std::tm nowTm = DateTimeUtility::getTime();

        nowTm.tm_sec = static_cast<IntEditor*> (editUnits[2].get())->getValue();
        nowTm.tm_min = static_cast<IntEditor*> (editUnits[1].get())->getValue();
        nowTm.tm_hour = static_cast<IntEditor*> (editUnits[0].get())->getValue();
        nowTm.tm_year = static_cast<IntEditor*> (editUnits[3].get())->getValue() - 1900;
        nowTm.tm_mon  = static_cast<IntEditor*> (editUnits[4].get())->getValue() - 1;
        nowTm.tm_mday = static_cast<IntEditor*> (editUnits[5].get())->getValue();

        mloopManager.mmanualModeKeepTime =  static_cast<IntEditor*> (editUnits[6].get())->getValue();
        //LOG_DEDUG("mmanualModeKeepTime:%d", mloopManager.mmanualModeKeepTime);

        CommandExecutorSingleton::instance().setSystemTime(nowTm);
}











